package com.fantasy.shares;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map.Entry;

import com.fantasy.mysql.GetConn;
import com.fantasy.mysql.SqlUtil;

/**
* @author Fantasy E-mail:vi2014@qq.com
* @version CreateDate：2017年2月26日 上午10:27:39
* 
*/
public class SaveSharesService {

	private static String saveTemplate = "insert into details set code = \"#{code}\" , name = \"#{name}\" "
			+ " , net_assets = \"#{net_assets}\" , net_rate  = \"#{net_rate}\" ,revenue = \"#{revenue}\" "
			+ " , An = \"#{An}\" , net_profit = \"#{net_profit}\" , debt_ratio = \"#{debt_ratio}\" "
			+ " , capital = \"#{capital}\" , tradable = \"#{tradable}\" , market = \"#{market}\"";
	
	public static void save(HashMap<String, String> data){
		String sql = saveTemplate;
		for (Entry<String, String> elem : data.entrySet()) {
			sql = sql.replace("#{" + elem.getKey() + "}", elem.getValue().trim());
		}
		try {
			SqlUtil.executeSql(GetConn.getSharesConn(), sql);
		} catch (SQLException e) {
			System.out.println("保存失败：" + sql);
			System.err.println("ERROR :" + e.getMessage());
		}
	}
	
}
